package org.mspring.mlog.service;

import org.mspring.mlog.cache.NodeCacheService;
import org.mspring.mlog.dao.NodeEntityDao;
import org.mspring.mlog.entity.NodeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gao Youbo
 * @since 2014-09-10 12:44:49
 */
@Service
public class NodeEntityService {

    private NodeEntityDao nodeEntityDao;
    private NodeCacheService nodeCacheService;

    @Transactional
    public boolean insert(NodeEntity node) {
        return nodeEntityDao.insert(node);
    }

    @Transactional
    public boolean update(NodeEntity node) {
        return nodeEntityDao.update(node);
    }

    @Transactional
    public boolean deleteById(long id) {
        return nodeEntityDao.deleteById(id);
    }

    /**
     * 删除所有
     *
     * @return
     */
    @Transactional
    public boolean deleteAll() {
        return nodeEntityDao.deleteAll();
    }

    /**
     * 根据角色查找角色对应的树形菜单
     *
     * @param roleId
     * @return
     */
    public List<NodeEntity> listByRole(long roleId) {
        return nodeEntityDao.listByRole(roleId);
    }

    @Autowired
    public void setNodeEntityDao(NodeEntityDao nodeEntityDao) {
        this.nodeEntityDao = nodeEntityDao;
    }

    @Autowired
    public void setNodeCacheService(NodeCacheService nodeCacheService) {
        this.nodeCacheService = nodeCacheService;
    }
}
